package com.supermap.originTest;


import com.supermap.data.*;
import com.supermap.mapping.Layer;
import com.supermap.mapping.Selection;
import com.supermap.ui.MapControl;

import javax.swing.*;
import java.awt.*;


public class TestSelection {

    private static JPanel m_jPanelDiagram;

    /**
     * 程序入口点
     * The entrance of the programme.
     */
    public static void main(String[] args) {


        
        Workspace workspace = new Workspace();
        WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(
                "E:\\MapData\\202407\\map\\anhui1.smwu");
        conInfo.setType(WorkspaceType.SMWU);
        workspace.open(conInfo);

        MapControl m_mapControl = new MapControl();
        m_mapControl.setLayout(null);
        m_mapControl.add(getJPanel());
        m_mapControl.getMap().setWorkspace(workspace);
        m_mapControl.setWaitCursorEnabled(false);




        DatasetVector datasetvector = (DatasetVector) workspace.getDatasources().get(1).getDatasets().get("anhui_road");
        Layer layer = m_mapControl.getMap().getLayers().add(datasetvector, true);

        int[] myArray = new int[500];
        for (int i = 0; i < 500; i++) {
            myArray[i] =i;
        }
        // 根据 ID 进行查询，返回查询结果记录集
        Recordset recordset = datasetvector.query(myArray, CursorType.STATIC);


        // 从该记录集获取选择集
        Selection selection = new Selection();
        selection.fromRecordset(recordset);

        System.out.println("选中的数据集的record数量:"+recordset.getRecordCount());
        System.out.println("选中的数据集的record数量:"+selection.toRecordset().getRecordCount());
        System.out.println("选中的数据集的总数量:"+selection.getCount());

        // 移除从序号1到10的几何对象
//        selection.removeRange(1, 10);

        // 设置选择集的风格
        GeoStyle style = new GeoStyle();
        style.setLineColor(Color.cyan);
        style.setLineSymbolID(5);
        style.setLineWidth(3.0);
        selection.setStyle(style);

        layer.setSelection(selection);
        m_mapControl.getMap().refresh();

        // 将选择集转化为记录集
//        Recordset recordset1 = selection.toRecordset();

        // 统计人口最大值
//        double maxValue = recordset1.statistic("maxspeed", StatisticMode.MAX);
//        System.out.println("人口最大值" + maxValue);
//
//        // 清空选择集
//        selection.clear();
//
//        // 释放资源
//        recordset1.dispose();
        recordset.dispose();
        selection.dispose();


    }



    private static JPanel getJPanel() {
        if (Environment.getCurrentCulture().contentEquals("zh-CN"))
        {
            if (m_jPanelDiagram == null) {

                // 设置面板的标题
                // Set the title of legend panel
                JLabel titleLLabel = new JLabel();
                titleLLabel.setHorizontalAlignment(JLabel.RIGHT);
                titleLLabel.setText(getText("titleLLabel"));
                JLabel titleRLabel = new JLabel();
                titleRLabel.setText(getText("titleRLabel"));
                //设置分段信息
                // Set the unique information
                JLabel jLabel0 = new JLabel();
                jLabel0.setText(getText("jLabel0"));
                jLabel0.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel0 = new JPanel();
                jPanel0.setBackground(new Color(206, 101, 156, 204));
                jPanel0.setPreferredSize(new Dimension(30, 20));

                JLabel jLabel1 = new JLabel();
                jLabel1.setText(getText("jLabel1"));
                jLabel1.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel1 = new JPanel();
                jPanel1.setBackground(new Color(181, 178, 181, 204));

                JLabel jLabel2 = new JLabel();
                jLabel2.setText(getText("jLabel2"));
                jLabel2.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel2 = new JPanel();
                jPanel2.setBackground(new Color(255, 255, 115, 115));

                JLabel jLabel3 = new JLabel();
                jLabel3.setText(getText("jLabel3"));
                jLabel3.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel3 = new JPanel();
                jPanel3.setBackground(new Color(254, 175, 136, 255));

                JLabel jLabel4 = new JLabel();
                jLabel4.setText(getText("jLabel4"));
                jLabel4.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel4 = new JPanel();
                jPanel4.setBackground(new Color(115, 77, 0));

                JLabel jLabel5 = new JLabel();
                jLabel5.setText(getText("jLabel5"));
                jLabel5.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel5 = new JPanel();
                jPanel5.setBackground(new Color(173, 170, 0));

                JLabel jLabel6 = new JLabel();
                jLabel6.setText(getText("jLabel6"));
                jLabel6.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel6 = new JPanel();
                jPanel6.setBackground(new Color(151, 219, 242));

                JLabel jLabel7 = new JLabel();
                jLabel7.setText(getText("jLabel7"));
                jLabel7.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel7 = new JPanel();
                jPanel7.setBackground(new Color(90, 138, 66, 125));

                JLabel jLabel8 = new JLabel();
                jLabel8.setText(getText("jLabel8"));
                jLabel8.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel8 = new JPanel();
                jPanel8.setBackground(new Color(0, 113, 74, 140));

                JLabel jLabel9 = new JLabel();
                jLabel9.setText(getText("jLabel9"));
                jLabel9.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel9 = new JPanel();
                jPanel9.setBackground(new Color(0, 170, 132, 204));

                JLabel jLabel10 = new JLabel();
                jLabel10.setText(getText("jLabel10"));
                jLabel10.setHorizontalAlignment(JLabel.CENTER);
                JPanel jPanel10 = new JPanel();
                jPanel10.setBackground(new Color(90, 179, 40, 90));

                // 初始化面板并添加组件
                // Initialze the legend panel and add components
                m_jPanelDiagram = new JPanel();
                m_jPanelDiagram.setSize(new Dimension(260, 260));
                m_jPanelDiagram.setLayout(new GridLayout(12, 2));
                m_jPanelDiagram.setBorder(BorderFactory
                        .createLineBorder(new Color(143, 198, 203), 1));
                m_jPanelDiagram.add(titleLLabel);
                m_jPanelDiagram.add(titleRLabel);
                m_jPanelDiagram.add(jPanel0);
                m_jPanelDiagram.add(jLabel0);
                m_jPanelDiagram.add(jPanel1);
                m_jPanelDiagram.add(jLabel1);
                m_jPanelDiagram.add(jPanel2);
                m_jPanelDiagram.add(jLabel2);
                m_jPanelDiagram.add(jPanel3);
                m_jPanelDiagram.add(jLabel3);
                m_jPanelDiagram.add(jPanel4);
                m_jPanelDiagram.add(jLabel4);
                m_jPanelDiagram.add(jPanel5);
                m_jPanelDiagram.add(jLabel5);
                m_jPanelDiagram.add(jPanel6);
                m_jPanelDiagram.add(jLabel6);
                m_jPanelDiagram.add(jPanel7);
                m_jPanelDiagram.add(jLabel7);
                m_jPanelDiagram.add(jPanel8);
                m_jPanelDiagram.add(jLabel8);
                m_jPanelDiagram.add(jPanel9);
                m_jPanelDiagram.add(jLabel9);
                m_jPanelDiagram.add(jPanel10);
                m_jPanelDiagram.add(jLabel10);
            }
        }
        else
        {
            if (m_jPanelDiagram == null) {

                // 设置面板的标题
                // Set the title of legend panel
                JLabel titleLLabel = new JLabel();
                titleLLabel.setHorizontalAlignment(JLabel.RIGHT);
                titleLLabel.setText(getText("titleLLabel"));
                JLabel titleRLabel = new JLabel();
                titleRLabel.setText(getText("titleRLabel"));
                //设置分段信息
                // Set the unique information
                JLabel jLabel0 = new JLabel();
                jLabel0.setText(getText("jLabel0"));
                jLabel0.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel0 = new JPanel();
                jPanel0.setBackground(new Color(206, 101, 156, 204));
                jPanel0.setPreferredSize(new Dimension(30, 20));

                JLabel jLabel1 = new JLabel();
                jLabel1.setText(getText("jLabel1"));
                jLabel1.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel1 = new JPanel();
                jPanel1.setBackground(new Color(181, 178, 181, 204));

                JLabel jLabel2 = new JLabel();
                jLabel2.setText(getText("jLabel2"));
                jLabel2.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel2 = new JPanel();
                jPanel2.setBackground(new Color(255, 255, 115, 115));

                JLabel jLabel3 = new JLabel();
                jLabel3.setText(getText("jLabel3"));
                jLabel3.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel3 = new JPanel();
                jPanel3.setBackground(new Color(254, 175, 136, 255));

                JLabel jLabel4 = new JLabel();
                jLabel4.setText(getText("jLabel4"));
                jLabel4.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel4 = new JPanel();
                jPanel4.setBackground(new Color(115, 77, 0));

                JLabel jLabel5 = new JLabel();
                jLabel5.setText(getText("jLabel5"));
                jLabel5.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel5 = new JPanel();
                jPanel5.setBackground(new Color(173, 170, 0));

                JLabel jLabel6 = new JLabel();
                jLabel6.setText(getText("jLabel6"));
                jLabel6.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel6 = new JPanel();
                jPanel6.setBackground(new Color(151, 219, 242));

                JLabel jLabel7 = new JLabel();
                jLabel7.setText(getText("jLabel7"));
                jLabel7.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel7 = new JPanel();
                jPanel7.setBackground(new Color(90, 138, 66, 125));

                JLabel jLabel8 = new JLabel();
                jLabel8.setText(getText("jLabel8"));
                jLabel8.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel8 = new JPanel();
                jPanel8.setBackground(new Color(0, 113, 74, 140));

                JLabel jLabel9 = new JLabel();
                jLabel9.setText(getText("jLabel9"));
                jLabel9.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel9 = new JPanel();
                jPanel9.setBackground(new Color(0, 170, 132, 204));

                JLabel jLabel10 = new JLabel();
                jLabel10.setText(getText("jLabel10"));
                jLabel10.setHorizontalAlignment(JLabel.LEFT);
                JPanel jPanel10 = new JPanel();
                jPanel10.setBackground(new Color(90, 179, 40, 90));

                // 初始化面板并添加组件
                // Initialze the legend panel and add components
                m_jPanelDiagram = new JPanel();
                m_jPanelDiagram.setSize(new Dimension(260, 260));
                m_jPanelDiagram.setLayout(new GridLayout(12, 2));
                m_jPanelDiagram.setBorder(BorderFactory
                        .createLineBorder(new Color(143, 198, 203), 1));
                m_jPanelDiagram.add(titleLLabel);
                m_jPanelDiagram.add(titleRLabel);
                m_jPanelDiagram.add(jPanel0);
                m_jPanelDiagram.add(jLabel0);
                m_jPanelDiagram.add(jPanel1);
                m_jPanelDiagram.add(jLabel1);
                m_jPanelDiagram.add(jPanel2);
                m_jPanelDiagram.add(jLabel2);
                m_jPanelDiagram.add(jPanel3);
                m_jPanelDiagram.add(jLabel3);
                m_jPanelDiagram.add(jPanel4);
                m_jPanelDiagram.add(jLabel4);
                m_jPanelDiagram.add(jPanel5);
                m_jPanelDiagram.add(jLabel5);
                m_jPanelDiagram.add(jPanel6);
                m_jPanelDiagram.add(jLabel6);
                m_jPanelDiagram.add(jPanel7);
                m_jPanelDiagram.add(jLabel7);
                m_jPanelDiagram.add(jPanel8);
                m_jPanelDiagram.add(jLabel8);
                m_jPanelDiagram.add(jPanel9);
                m_jPanelDiagram.add(jLabel9);
                m_jPanelDiagram.add(jPanel10);
                m_jPanelDiagram.add(jLabel10);
            }
        }
        return m_jPanelDiagram;
    }


    private static String getText(String id){
        return "abcd";
    }


}  

